package com.crazyhat.crazyhat.vaildation;

import org.springframework.stereotype.Component;

import com.crazyhat.crazyhat.anno.ClubPostPublicScopeAnno;
import com.crazyhat.crazyhat.attribute.PostPublicScopeEnum;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import lombok.Data;

/**
 * 社区动态公开范围校验
 */
@Component
@Data
public class ClubPostPublicScopeValidation implements ConstraintValidator<ClubPostPublicScopeAnno, PostPublicScopeEnum>{

    // @Override
    // public boolean isValid(String value, ConstraintValidatorContext context) {
    //     if (value == null) {
    //         return false;
    //     }

    //     for (PostPublicScopeEnum scope :PostPublicScopeEnum.values()) {
    //         if (scope.getValue().equals(value)) {
    //             return true;
    //         }
    //     }
    //     return false;
    // }

    @Override
    public boolean isValid(PostPublicScopeEnum value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }

        for (PostPublicScopeEnum scope :PostPublicScopeEnum.values()) {
            if (scope.equals(value)) {
                return true;
            }
        }
        return false;
    }
}
